home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / Command.h < prev    next >
Encoding:
Text File  |  1995-12-11  |  3.3 KB  |  118 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Command.h
  3.  
  4.     Contains:    Command Classes Definition
  5.  
  6.     Written by:    Dave Stafford
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- Compiler/Preprocessor Switches --
  12.  
  13. #ifndef _COMMAND_
  14. #define _COMMAND_
  15.  
  16. #ifndef _COMPILERDEFS_
  17. #include "CompDefs.h"
  18. #endif
  19.  
  20. #ifndef _DRAWEDITORDEF_
  21. #include "DrawEditorDef.h"
  22. #endif
  23.  
  24. //=============================================================================
  25. // Forward Declarations
  26. //=============================================================================
  27. class DrawEditor;
  28.  
  29. //=============================================================================
  30. // Constants
  31. //=============================================================================
  32.  
  33. //=============================================================================
  34. // Enumerations
  35. //=============================================================================
  36.  
  37.  
  38. //=============================================================================
  39. // CCommand
  40. //
  41. // Assumptions: 
  42. // The command object assumes that for all Begin/End action pairs, the SAME
  43. // command object will be used. In this case, null is written out for the begin
  44. // action, and the this pointer for the command is written out for all other 
  45. // action types. This also means that commit will only be called once on such
  46. // commands.
  47. //
  48. //=============================================================================
  49. class CCommand
  50. {
  51. public:
  52.     
  53.     // -- Init --
  54.     CCommand(DrawEditor* theEditor, 
  55.                 ODBoolean canUndo = kODFalse,
  56.                 ODBoolean changesContent = kODFalse,
  57.                 ODID undoTextIndex = kUndoCommandIndex,
  58.                 ODID redoTextIndex = kRedoCommandIndex);
  59.     
  60.     virtual ~CCommand();
  61.  
  62. public:
  63.  
  64.     // -- Accessors --
  65.     void             SetChangesContent(ODBoolean changesContent);
  66.     
  67.     void             SetMenuTextIDs(ODID undoTextIndex, ODID redoTextIndex);
  68.         
  69.     ODBoolean        CanUndo() const;
  70.     ODBoolean        ChangesContent() const;
  71.     ODCommandID        GetCommandID() const;
  72.     
  73.     // -- Actions --
  74.     void            SetActionType(ODActionType actionType);
  75.     ODActionType    GetActionType() const;
  76.     void            WriteAction(Environment* ev, ODActionType actionType);
  77.     void            AbortCommand(Environment* ev);
  78.     
  79.     // Undo-able commands
  80.     // Should call inherited in derivative classes
  81.     virtual void    UndoCommand(Environment* ev);
  82.     virtual void     RedoCommand(Environment* ev);
  83.     
  84.     // Is called from DoCommand. Used to store information
  85.     // about the command ( shapelists, etc. ).
  86.     virtual void     CaptureCommandState(Environment* ev);
  87.     
  88.     // Called just before the command is deleted.
  89.     virtual void     Commit(Environment* ev, ODDoneState state);
  90.     
  91.     // -- Must Override this method --
  92.     // This method should only be called once per instance
  93.     // Should call inherited in derivative classes
  94.     virtual void     DoCommand(Environment* ev);
  95.     
  96.  
  97. //----------------------------------------------------------------------------------------
  98. // Data Members
  99. //
  100. protected:
  101.     ODBoolean        fCanUndo;            // Default True
  102.     ODBoolean        fChangesContent;    // Default True
  103.     ODActionType    fActionType;        // Default = kODSingleAction
  104.     DrawEditor*        fDrawEditor;
  105.     ODFrame*        fFrame;                // Can be NULL
  106.  
  107. private:
  108.     ODUndo*        fUndo;
  109.     ODDoneState    fDoneState;                    // doneState values are kODDone, kODUndone, or kODRedone (ODTypes.h)
  110.  
  111.     ODID        fUndoTextIndex;                // For Undo menu item. Default: kUndoCommandIndex
  112.     ODID        fRedoTextIndex;                // For Redo menu item. Default: kRedoCommandIndex
  113. };
  114.  
  115.  
  116.  
  117.  
  118. #endif